home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 October / CHIP Turkiye Ekim 2000.iso / prog / naps / 04 / setup.exe / Gnucleus / PrefLanguage.cpp < prev    next >
C/C++ Source or Header  |  2000-07-15  |  7KB  |  235 lines

  1. /********************************************************************************
  2.  
  3.     Gnucleus - A node application for the Gnutella network
  4.     Copyright (C) 2000 John Marshall
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     For support, questions, comments, etc...
  20.     E-Mail: 
  21.         swabby@c0re.net
  22.     
  23.     Address:
  24.         21 Cadogan Way
  25.         Nashua, NH, USA 03062
  26.  
  27. ********************************************************************************/
  28.  
  29. // PrefLanguage.cpp : implementation file
  30. //
  31.  
  32. #include "stdafx.h"
  33. #include "Gnucleus.h"
  34. #include "GnucleusDoc.h"
  35. #include "PrefLanguage.h"
  36.  
  37. #ifdef _DEBUG
  38. #define new DEBUG_NEW
  39. #undef THIS_FILE
  40. static char THIS_FILE[] = __FILE__;
  41. #endif
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CPrefLanguage property page
  45.  
  46. IMPLEMENT_DYNCREATE(CPrefLanguage, CPropertyPage)
  47.  
  48. CPrefLanguage::CPrefLanguage() : CPropertyPage(CPrefLanguage::IDD)
  49. {
  50.     Doc = NULL;
  51.  
  52.     //{{AFX_DATA_INIT(CPrefLanguage)
  53.         // NOTE: the ClassWizard will add member initialization here
  54.     //}}AFX_DATA_INIT
  55. }
  56.  
  57. CPrefLanguage::~CPrefLanguage()
  58. {
  59. }
  60.  
  61. void CPrefLanguage::DoDataExchange(CDataExchange* pDX)
  62. {
  63.     CPropertyPage::DoDataExchange(pDX);
  64.     //{{AFX_DATA_MAP(CPrefLanguage)
  65.     DDX_Control(pDX, IDC_BUTTON_ACTIVATE, m_btnActivate);
  66.     DDX_Control(pDX, IDC_BUTTON_UPDATE, m_btnUpdate);
  67.     DDX_Control(pDX, IDC_LIST_SELECT, m_lstSelect);
  68.     //}}AFX_DATA_MAP
  69. }
  70.  
  71.  
  72. BEGIN_MESSAGE_MAP(CPrefLanguage, CPropertyPage)
  73.     //{{AFX_MSG_MAP(CPrefLanguage)
  74.     ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate)
  75.     ON_BN_CLICKED(IDC_BUTTON_ACTIVATE, OnButtonActivate)
  76.     //}}AFX_MSG_MAP
  77. END_MESSAGE_MAP()
  78.  
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CPrefLanguage message handlers
  81.  
  82. BOOL CPrefLanguage::OnInitDialog() 
  83. {
  84.     CPropertyPage::OnInitDialog();
  85.     
  86.     Doc = (CGnucleusDoc *) ((CGnucleusApp *) AfxGetApp())->MasterDoc;
  87.  
  88.     CRect rect;    
  89.  
  90.     // Setup shared list
  91.     m_lstSelect.GetWindowRect(&rect);
  92.  
  93.     m_lstSelect.InsertColumn(0, "Module", LVCFMT_LEFT,
  94.         (rect.Width() - 30) * 2/3, 0);
  95.     m_lstSelect.InsertColumn(1, "Version", LVCFMT_LEFT,
  96.         (rect.Width() - 30) * 1/3, 1);
  97.  
  98.     m_lstSelect.SetExtendedStyle(LVS_EX_FULLROWSELECT);
  99.  
  100.     // Get language DLL's in current directory
  101.     OnButtonUpdate();
  102.     
  103.     m_btnUpdate.EnableWindow(TRUE);
  104.  
  105.  
  106.     return TRUE;  // return TRUE unless you set the focus to a control
  107.                   // EXCEPTION: OCX Property Pages should return FALSE
  108. }
  109.  
  110. ////////////////////////////////////////////////////////////
  111. //! author="Nathan Brown"
  112. //
  113. //: Update the language list by looking in the current directory
  114. //: for Language DLL's.
  115. void CPrefLanguage::OnButtonUpdate() 
  116. {
  117.     // Get language DLL's in current directory
  118.  
  119.     CFileFind finder;
  120.     FOUR64BIT version_num;
  121.     CString buffer;
  122.  
  123.     version_num.dw64 = 0;
  124.  
  125.     BOOL b_more_files = true;
  126.     bool b_found_lang_pack = false;
  127.  
  128.     m_lstSelect.DeleteAllItems();
  129.  
  130.     b_more_files = finder.FindFile("GNU_Lang_*.DLL");
  131.  
  132.     while(b_more_files)
  133.     {
  134.         b_found_lang_pack = true;
  135.  
  136.         b_more_files = finder.FindNextFile();
  137.  
  138.         version_num.dw64 = util_GetVersionNumber((LPCTSTR)finder.GetFilePath());
  139.         buffer.Format("%u.%u.%u.%u", version_num.i1, version_num.i2, version_num.i3, version_num.i4);
  140.  
  141.         m_lstSelect.InsertItem(0, (LPCTSTR)finder.GetFileName());
  142.         m_lstSelect.SetItem(0, 1, LVIF_TEXT, buffer, NULL, NULL, NULL, NULL);
  143.     }
  144.  
  145.     // Now insert the default english selection
  146.     version_num.dw64 = util_GetVersionNumber("gnucleus.exe");
  147.     buffer.Format("%u.%u.%u.%u", version_num.i1, version_num.i2, version_num.i3, version_num.i4);
  148.     m_lstSelect.InsertItem(0, "Default (English)");
  149.     m_lstSelect.SetItem(0, 1, LVIF_TEXT, buffer, NULL, NULL, NULL, NULL);
  150.  
  151.     if(b_found_lang_pack)
  152.         m_btnActivate.EnableWindow(TRUE);
  153.     else
  154.         m_btnActivate.EnableWindow(FALSE);
  155. }
  156.  
  157. ////////////////////////////////////////////////////////////
  158. //! author="Nathan Brown"
  159. //
  160. //: Grabs the the selected language, and sets the program to those
  161. //: setting, saves the INI, and then applys if possible
  162. void CPrefLanguage::OnButtonActivate() 
  163. {
  164.  
  165.     if(m_lstSelect.GetSelectedCount())
  166.     {
  167.  
  168.         // Load new resource Dll as selected by user 
  169.         CString str_lib_name = m_lstSelect.GetItemText( m_lstSelect.GetSelectionMark(), 0);
  170.  
  171.         // handle default string
  172.         if(str_lib_name.Find("Default") != -1 || str_lib_name.Find("GNU_Lang") == -1)
  173.             Doc->m_strLangDLLex = "Default";
  174.         else
  175.             Doc->m_strLangDLLex = str_lib_name.Mid(str_lib_name.GetLength() - 7, 3);
  176.  
  177.         // Don't apply midstream right now, because it doesn't work fully.
  178.         // Require the user to restart instead.
  179.         AfxMessageBox("Please restart program to apply changes.\n");
  180. //        CPrefLanguage::SwitchLanguge(Doc);
  181.  
  182.         Doc->WriteINI();
  183.     }
  184. }
  185.  
  186. BOOL CPrefLanguage::OnApply() 
  187. {
  188.     // TODO: Add your specialized code here and/or call the base class
  189.     
  190.     return CPropertyPage::OnApply();
  191. }
  192.  
  193. ////////////////////////////////////////////////////////////
  194. //! author="Nathan Brown"
  195. //
  196. //: Performs a program wide Language switch by loading and unloading
  197. //: a language DLL.
  198. void CPrefLanguage::StaticSwitchLanguge(CGnucleusDoc * Doc)
  199. {
  200.         if(Doc->m_hLangDLL)
  201.         {
  202.             FreeLibrary(Doc->m_hLangDLL);
  203.             Doc->m_hLangDLL = NULL;
  204.         }
  205.  
  206.         if(!Doc->m_strLangDLLex.IsEmpty() && Doc->m_strLangDLLex.Find("Default") == -1)
  207.         {
  208.             CString str_lib_name = "GNU_Lang_" + Doc->m_strLangDLLex + ".DLL";
  209.  
  210.             Doc->m_hLangDLL = AfxLoadLibrary(str_lib_name);
  211.  
  212.             ASSERT(Doc->m_hLangDLL);
  213.             AfxSetResourceHandle(Doc->m_hLangDLL);
  214.  
  215.  
  216.     /*
  217.         // now update main menu 
  218.         HMENU hmen = ::LoadMenu( Doc->m_hLangDLL, MAKEINTRESOURCE(IDR_MAINFRAME)); 
  219.         HWND mainwnd = AfxGetMainWnd()->m_hWnd; 
  220.         if (::IsWindow(mainwnd) && m_pParentWnd) 
  221.         { 
  222.             ::SetMenu(mainwnd, hmen); 
  223.             AfxGetMainWnd()->DrawMenuBar( ); 
  224.         } 
  225. */
  226. /*
  227.         else 
  228.             // errorhandling 
  229.             // Set idle message in statusbar 
  230.             AfxGetMainWnd()->SendMessage(WM_SETMESSAGESTRING, (WPARAM)AFX_IDS_IDLEMESSAGE, 0L); 
  231. */
  232.  
  233.         }
  234.  
  235. }